package com.study.string;

import java.util.Arrays;

public class StringAPIOtherDemo6 {
    public static void main(String[] args) {
        String name = "我爱你中国!";
        //  1.public int length():获取字符串的长度
        System.out.println(name.length());
        //  2.public char charAt() 获取某个索引处的字符
        char c = name.charAt(1);
        System.out.println(c);
        for (int i = 0; i < name.length(); i++) {
            char c1 = name.charAt(i);
            System.out.println(c1);
        }
        //   3.public char[] toCharArray():把字符串转换成字符数组
        char[] chars = name.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            System.out.println(chars[i]);
        }
        //   4.public String substring(int beginIndex,int endIndex):截取内容包前不包后
        String name2 = "Java是最厉害的编程语言！";
        String substring = name2.substring(0, 9);
        System.out.println(substring);
        //   5.public String substring(int endIndex）:从当前索引一直截取到末尾
        String substring1 = name2.substring(4);
        System.out.println(substring1);
        //   6.public String replace(CharSequence target,CharSequence target):字符串替换
        String s1= "金三胖是最厉害的80后，金三胖棒棒的！我好爱金三胖";
        String s2 = s1.replace("金三胖", "***");
        System.out.println(s2);
        //   7.public boolean contains(CharSequence s)判断是否包含指定字符串
        System.out.println(s1.contains("金三胖"));
        //   8.public boolean startsWiths(String prefix)判断是否以指定字符串开头
        System.out.println(s1.startsWith("金三胖"));
        //   9.public String[] split(String s):按照某个内容把字符串分割成字符串数组并返回。
        String s3 = "折木奉太郎,绫小路清隆,比企谷八幡,梓川咲太";
        String[] names = s3.split(",");
        System.out.println(Arrays.toString(names));

    }
}
